GN group
A group
in GN is essentially a collection of other targets. It doesn't define any build outputs itself but is used to bundle a set of dependencies together. This can be useful for organizing related targets or creating meta-targets that build several things at once.
In GN, a “group” is just a collection of dependencies that’s not complied or linked.
Definition
A group
is defined much like any other target in GN. It starts with the group
keyword followed by the target's name.
group("my_group") {
...
}
Dependencies
Inside the group block, you can specify a list of dependencies. These dependencies can be other targets like source_set
, executable
, shared_library
, etc. When the group is built, GN ensures that all of its dependencies are also built.
group("my_group") {
deps = [
":dependency1",
"//path/to:dependency2",
"//another/path:dependency3",
]
}
Visibility
Like other targets, a group
can have visibility rules defining which other targets can depend on it. This is useful for controlling the accessibility of a set of targets.
group("my_group") {
visibility = [":some_other_target"]
...
}
Purpose
Groups are often used for:
- Aggregating Targets: Simplifying build scripts by combining multiple targets into a single target.
- Organizing Code: Grouping related targets for better readability and structure.
- Managing Dependencies: Encapsulating a set of dependencies that are commonly used together.
Building
When you build a group
, GN doesn't generate any build output for the group itself. Instead, it ensures that all of the dependencies of the group are built. This is done by generating appropriate build rules in the Ninja build file.
Remember, group
targets don't directly correspond to any file or build artifact. They are purely organizational within the build system to manage and relate different build targets.
本文作者:Maeiee
本文链接:GN group
版权声明:如无特别声明,本文即为原创文章,版权归 Maeiee 所有,未经允许不得转载!
喜欢我文章的朋友请随缘打赏,鼓励我创作更多更好的作品!